#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int n;
    cin >> n;
    int sum;
    cin >> sum;
    int maxx = sum;
    for (int i=2; i<=n; ++i)
    {
        int inp;
        scanf("%d", &inp);
        sum += inp;
        maxx = maxx>sum ? maxx:sum;
        if (sum <0) sum = 0;

    }
    cout << maxx;
}
/*
10
1 2 3 4 5 -1 -2 -3 -4 -5

2
-2 -1

2
-1 -2

2
1 2

2
0 0

*/
